package app.beit.finportal.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import app.beit.finportal.bean.AccountBean;
import app.beit.finportal.dao.AccountDao;
import app.beit.finportal.entity.Account;
import app.beit.finportal.service.convert.AccountConvert;

public class AccountService {

	@Autowired
	private AccountDao accountDao;
	
	public List<AccountBean> getAccount(final String username, final String password) throws Exception{
		final List<Account> entities = this.accountDao.getAccount(username, password);
		if(entities != null && entities.size() > 0){
			return AccountConvert.entityToBean(entities);
		}
		
		return null;
	}

	public List<AccountBean> getAccount(final String username) throws Exception{
		final List<Account> entities = this.accountDao.getAccount(username);
		if(entities != null && entities.size() > 0){
			return AccountConvert.entityToBean(entities);
		}
		
		return null;
	}
	
	public List<AccountBean> getAll() throws Exception{
		final List<Account> entities = this.accountDao.getAll();
		if(entities != null && entities.size() > 0){
			return AccountConvert.entityToBean(entities);
		}
		
		return null;
	}
	
	public void add(final AccountBean bean) throws Exception{
		this.accountDao.add(AccountConvert.beanToEntity(bean));
	}
	
	public void update(final AccountBean bean) throws Exception{
		this.accountDao.update(AccountConvert.beanToEntity(bean));
	}
	
	public void delete(final AccountBean bean) throws Exception{
		this.accountDao.delete(AccountConvert.beanToEntity(bean));
	}
	
}
